package com.wing.order.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.order.dao.CabInventoryProductRecordDao;
import com.wing.order.model.entity.CabInventoryProductRecord;
import com.wing.order.model.request.CabInventoryProductRecordForm;
import com.wing.order.model.response.CabInventoryProductRecordVO;
import com.wing.order.model.response.MaterialInventoryStatisticsReportVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 产品库存变动记录-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class CabInventoryProductRecordServiceImpl extends ServiceImpl<CabInventoryProductRecordDao, CabInventoryProductRecord> implements CabInventoryProductRecordService {

    @Override
    public int add(CabInventoryProductRecordForm cabInventoryProductRecordForm) {

        //校验

        CabInventoryProductRecord cabInventoryProductRecord =new CabInventoryProductRecord();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(CabInventoryProductRecord.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(cabInventoryProductRecordForm, cabInventoryProductRecord, copyOptions);

        return baseMapper.insert(cabInventoryProductRecord);
    }

    @Override
    public List<CabInventoryProductRecordVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<CabInventoryProductRecordVO> pageList4app(Page page, Map<String, Object> params) {
        List<CabInventoryProductRecordVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public CabInventoryProductRecordVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public Page<CabInventoryProductRecordVO> statisticsReport(Page page, Map<String, Object> params) {
        List<CabInventoryProductRecordVO> list = baseMapper.statisticsReport(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<CabInventoryProductRecordVO> statisticsReport(Map<String, Object> params) {
        return baseMapper.statisticsReport(params);
    }

    @Override
    public List<Long> getWarehouseList(String skuCode, String startCreateTime, String endCreateTime) {
        return baseMapper.getWarehouseList(skuCode, startCreateTime, endCreateTime);
    }

    @Override
    public Integer getOpeningQuantity(Long warehouseId, String skuCode, String startCreateTime) {
        return baseMapper.getOpeningQuantity(warehouseId, skuCode, startCreateTime);
    }

    @Override
    public Integer getOpeningPackQuantity(Long warehouseId, String skuCode, String startCreateTime) {
        return baseMapper.getOpeningPackQuantity(warehouseId, skuCode, startCreateTime);
    }

    @Override
    public Integer getBalanceQuantity(Long warehouseId, String skuCode, String endCreateTime) {
        return baseMapper.getBalanceQuantity(warehouseId, skuCode, endCreateTime);
    }

    @Override
    public Integer getBalancePackQuantity(Long warehouseId, String skuCode, String endCreateTime) {
        return baseMapper.getBalancePackQuantity(warehouseId, skuCode, endCreateTime);
    }

    @Override
    public List<MaterialInventoryStatisticsReportVO> export(Map<String, Object> params) {
        return baseMapper.export(params);
    }
}
